package org.ldx.lotterysystem.common.handler;

import lombok.extern.slf4j.Slf4j;
import org.ldx.lotterysystem.common.errorcode.GlobalErrorCodeConstants;
import org.ldx.lotterysystem.common.exception.ControllerException;
import org.ldx.lotterysystem.common.exception.ServiceException;
import org.ldx.lotterysystem.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = ServiceException.class)
    public CommonResult<?> ServiceException(ServiceException e){
      log.error("ServiceException e:"+e);
      return CommonResult.error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), e.getMessage());
    }
    @ExceptionHandler(value = ControllerException.class)
    public CommonResult<?> ControllerException(ControllerException e){
        log.error("ControllerException e:"+e);
        return CommonResult.error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), e.getMessage());
    }
    @ExceptionHandler(value = Exception.class)
    public CommonResult<?> exception(Exception e){
        log.error("exception e:"+e);
        return CommonResult.error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), e.getMessage());
    }
}
